package com.cskaoyan.market.service.impl;

import com.cskaoyan.market.db.domain.*;
import com.cskaoyan.market.db.mapper.MarketCollectMapper;
import com.cskaoyan.market.db.mapper.MarketFootprintMapper;
import com.cskaoyan.market.service.AdminFootprintService;
import com.cskaoyan.market.util.MybatisUtil;
import com.github.pagehelper.PageHelper;
import org.apache.commons.lang3.StringUtils;
import org.apache.ibatis.session.SqlSession;

import java.util.List;

public class AdminFootprintServiceImpl implements AdminFootprintService {
    @Override
    public List<MarketFootprint> list(String page, String limit, String userId, String goodsId, String sort, String order) {
        SqlSession session = MybatisUtil.getSession();
        MarketFootprintMapper mapper = session.getMapper(MarketFootprintMapper.class);
        MarketFootprintExample marketFootprintExample = new MarketFootprintExample();
        MarketFootprintExample.Criteria criteria = marketFootprintExample.createCriteria();
        if(!StringUtils.isEmpty(userId))
            criteria.andUserIdEqualTo(Integer.parseInt(userId));
        if(!StringUtils.isEmpty(goodsId))
            criteria.andUserIdEqualTo(Integer.parseInt(goodsId));
        marketFootprintExample.setOrderByClause(sort + " " + order);
        PageHelper.startPage(Integer.parseInt(page),Integer.parseInt(limit));
        List<MarketFootprint> marketFootprints = mapper.selectByExample(marketFootprintExample);
        session.commit();
        session.close();
        return marketFootprints;
    }
}
